﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;

namespace YJKOpeningDesignInput.Public
{
	internal class SolidFilter
	{
		public static Solid CreateSolid(Autodesk.Revit.DB.Document doc, BoundingBoxXYZ boundingBoxXYZ, double hight, double Level)
		{
			Solid result = null;
			XYZ xyz = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, Level);
			XYZ xyz2 = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, Level);
			XYZ xyz3 = new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, Level);
			XYZ xyz4 = new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Min.Y, Level);
			CurveLoop curveLoop = new CurveLoop();
			curveLoop.Append(Line.CreateBound(xyz, xyz2));
			curveLoop.Append(Line.CreateBound(xyz2, xyz3));
			curveLoop.Append(Line.CreateBound(xyz3, xyz4));
			curveLoop.Append(Line.CreateBound(xyz4, xyz));
			List<CurveLoop> list = new List<CurveLoop>();
			list.Add(curveLoop);
			using (Transaction transaction = new Transaction(doc, "Solid"))
			{
				transaction.Start();
				result = GeometryCreationUtilities.CreateExtrusionGeometry(list, XYZ.BasisZ, hight);
				transaction.Commit();
			}
			return result;
		}

		public static FilteredElementCollector GetIntersectsSolid(Autodesk.Revit.DB.Document doc, Solid solid, FilteredElementCollector collector)
		{
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(solid, false);
			collector.WherePasses(elementIntersectsSolidFilter);
			return collector;
		}
	}
}
